#include "qprocesstask.h"
#include <QDebug>

QProcessTask::QProcessTask(QJsonObject task, QObject *parent): QProcess(parent), m_task(task)
{
    Q_ASSERT(!task.isEmpty() && task.contains("id") && !task["id"].toString().isEmpty());
    connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SIGNAL(taskFinished(int, QProcess::ExitStatus)));

    startTimer(7000);
}

QProcessTask::~QProcessTask()
{
    qDebug()<<"Process destroy";
}

QJsonObject QProcessTask::task() const
{
    return m_task;
}

void QProcessTask::SLT_CancelTask(QString task_id)
{
    qDebug() << "SLT_CancelTask" << task_id;
    if (task_id == m_task.value("id").toString()) {
        kill();
    }
}

void QProcessTask::timerEvent(QTimerEvent *event)
{
    Q_UNUSED(event);

    qDebug() << "heart on " << m_task["id"];

    emit SIG_heart(m_task["id"].toString());
}

